<?php
require_once dirname(dirname(__FILE__)) . '/config/config.php';
require_once DOCUMENT_ROOT . DIR_SHARED_DAO . "dao_document_category.php";
require_once DOCUMENT_ROOT . DIR_SHARED_DAO . "dao_news_category.php";


class api_multi_level {
    
    public static function get_expand_id_list($chosen_category_id, $dao, $parent_key, $get_value_key) {
        $list = array();
        
        $category = $dao->get_by_id($chosen_category_id);
        
        $list[sizeof($list)] = $chosen_category_id;
//        var_dump($category);
//        var_dump($list);
        while (!empty($category[$parent_key])) {
            $category = $dao->get_by_id($category[$parent_key]);
            $list[sizeof($list)] = $category[$get_value_key];
        }
        return $list;
    }
    
    public static function get_root_document_categories() {
        $document_category_access = new dao_document_category();
        return $document_category_access->get_root_categories();
    } 
    
    public static function get_root_news_categories() {
        $news_category_access = new dao_news_category();
        return $news_category_access->get_root_categories();
    } 
    
    public static function get_expand_id_list_document_category($chosen_category_id) {
        $document_category_access = new dao_document_category();
        $expand_id_list = self::get_expand_id_list($chosen_category_id, $document_category_access, 'cat_parent_id', 'cat_id');
        return $expand_id_list;
    }
    
    public static function get_expand_id_list_news_category($chosen_category_id) {
        $news_category_access = new dao_news_category();
        $expand_id_list = self::get_expand_id_list($chosen_category_id, $news_category_access, 'parent_cat_news', 'cat_news_id');
        return $expand_id_list;
    }
    
    public static function get_document_categories_by_parent_id($parent_id) {
        $document_category_access = new dao_document_category();
        return $document_category_access->get_all_children_by_parent_id($parent_id);
    }
    
    public static function get_news_categories_by_parent_id($parent_id) {
        $news_category_access = new dao_news_category();
        return $news_category_access->get_all_children_by_parent_id($parent_id);
    }
}
